// @ts-ignore
/* eslint-disable */
import { notLoginResHandler, showLoginModal } from '@/utils';
import { request } from '@umijs/max';
const BASE_URL = 'https://wangyiyunapi-k0b30nc09-sole-badguy.vercel.app/';

/** 退出登录接口 POST /api/login/outLogin */
export async function outLogin(options?: { [key: string]: any }) {
  return request<Record<string, any>>('/api/logout', {
    method: 'DELETE',
    ...(options || {}),
  });
}
/**
 * 获取微信登录二维码
 * @param
 * @returns
 */
export async function getWXQRCode() {
  return request<COMMON.BaseSuccess<COMMON.QrCodeType>>('/api/security/wx/wxlogin', {
    method: 'GET',
  });
}

export async function weixinLogin(param: string) {
  return request<COMMON.BaseSuccess<string>>(`/api/security/wx/getToken/${param}`, {
    method: 'GET',
    param,
  });
}

// 根据id获取用户基本信息
export async function findUser(userId: number) {
  return request<COMMON.BaseSuccess<USERAPI.UserInfo>>(`/api/portal/user/findUser`, {
    method: 'GET',
    params: {
      userId,
    },
  });
}
// 查看当前登陆人拥有的文章收藏夹列表
export async function findArticleCollectRecordFile() {
  return request<COMMON.BaseSuccess<USER.ArticleCollectT[]>>(
    `/api/portal/article-collect-record-file/findArticleCollectRecordFile
  `,
    {
      method: 'GET',
    },
  );
}
// 创建收藏夹
export async function createArticleCollectRecordFile(data: USERAPI.CreateArticleCollectT) {
  return request<COMMON.BaseSuccess>(
    `/api/portal/article-collect-record-file/createArticleCollectRecordFile
  `,
    {
      method: 'POST',
      data,
    },
  );
}
// 签到
export async function signIn(): Promise<COMMON.BaseSuccess> {
  return showLoginModal(
    request(`/api/portal/sign-in-from/sign`, {
      method: 'POST',
    }),
  );
}
// 获取连续签到天数
export async function getSignInDay(): Promise<COMMON.BaseSuccess<number>> {
  return notLoginResHandler(() =>
    request(`/api/portal/sign-in-from/checkSignedDays`, {
      method: 'GET',
    }),
  );
}

// 获取签到记录
export async function getSignInRecord() {
  return request<COMMON.BaseSuccess<USER.SignInRecordT[]>>(
    `/api/portal/sign-in-from/findSignInRecord`,
    {
      method: 'GET',
    },
  );
}
// 获取今天是否签到
export async function findTodayHaveSing(): Promise<COMMON.BaseSuccess<number>> {
  return notLoginResHandler(() =>
    request(
      `/api/portal/sign-in-from/findTodayHaveSing
`,
      {
        method: 'GET',
      },
    ),
  );
}

export async function qqLogin(): Promise<COMMON.BaseSuccess<any>> {
  return request(`/api/authorization/qq/login`, {
    method: 'GET',
  });
}

export async function qqCallback(params: USERAPI.QQLoginT): Promise<
  COMMON.BaseSuccess<
    COMMON.TokenType & {
      tokenSurvivalTime?: number;
    }
  >
> {
  return request(`/api/authorization/qq/callback`, {
    method: 'GET',
    params: params,
    cache: false, //不缓存
  });
}

// 解绑QQ号
export async function qqCancel(): Promise<COMMON.BaseSuccess> {
  return request(`/api/authorization/qq/cancel`, {
    method: 'GET',
  });
}

// 验证手机号码是否正确
export async function qqBindingCode(params: any): Promise<COMMON.BaseSuccess> {
  return request(`/api/authorization/qq/bindingCode`, {
    method: 'GET',
    params,
  });
}

// 绑定QQ号
export async function qqBinding(params: any): Promise<COMMON.BaseSuccess> {
  return request(`/api/authorization/qq/binding`, {
    method: 'GET',
    params,
    cache: false, //不缓存
  });
}
